<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<title>邀请码配置</title>
<@fm.header />
<script>
function doSearch(){    
    $('#tt').datagrid('load', {    
        mark: $('#mark').val()    
    });
}

function add(){
    showMyWindow('新增配置', '/invite/code/config/add', 400, 400);
}

function edit(){
	var row = $('#tt').datagrid('getSelected');
    if (row){
	    showMyWindow('编辑', '/invite/code/config/'+row.id+'/update', 400, 300);
    } else {
    	showMsg(market.content.title, market.content.tips, alert);
    }
}

function del(){
	var row = $('#tt').datagrid('getSelected');
    if (row){
	   showConfirm(market.content.title, market.content.confirm, function(){
		  $.post('/invite/code/config/'+row.id+'/delete', function(data) {
		  	if (data.return_code == '1') {
				top.showMsg(market.content.title, data.return_msg, alert);
				$("#tt").datagrid('reload');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		  });
	   });
    } else {
    	showMsg(market.content.title, market.content.tips, alert);
    }
}

function formatTotalCount(value,row,index) {
	var totalCount = row.totalCount;
	if (totalCount.indexOf('-') >= 0) {
		var strs= new Array()
		strs = totalCount.split("-");
		return "<a href='javascript:void(0)' onclick='openWindow(" + strs[0] + "," + strs[1] + "," + row.id + ")')>" + row.totalCount + "</a>";
	}
}

function openWindow (start, end, id) {
	showMyWindow('概率配置', '/invite/code/config/configProbability/' + start + '/' + end + '/'+ id , 400, 400);
}
</script>
</head>
<body class="cmp-list-body">
<div id="tb" style="padding:3px">
    <span>Mark:</span>    
    <input id="mark" style="line-height:20px;border:1px solid #ccc">
    <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch();">查询</a> 
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add();">新增</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del();">删除</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit();">修改</a>
</div>
<table id="tt" class="easyui-datagrid" title="邀请码管理 | 邀请码列表" iconCls="icon-save" 
	url="/invite/code/config/listJson" toolbar="#tb" rownumbers="true" singleSelect="true" pagination="true" fitColumns="true" pageSize="15" pageList="[15,30,60,80,100]">    
    <thead>
        <tr>
            <th align="center" width="40%" field="mark">Mark</th>  
            <th align="center" width="20%" field="totalCount" formatter="formatTotalCount">总量</th> 
            <!--<th align="center" width="20%" field="totalCountAvg">平均总量</th>-->
            <!--<th align="center" width="20%" field="rateFirst">父概率</th>-->
            <th align="center" width="20%" field="rateSecond">子概率</th>
            <th align="center" width="20%" field="rateThird">孙概率</th>
            <th align="center" width="20%" field="rateFourth">后代剩余概率</th>
            <!--<th align="center" width="20%" field="probability">总概率</th>-->
        </tr>
    </thead>   
</table>
</body>
</html>